import { Init, Provide } from '@midwayjs/decorator';
import { BaseService } from '@cool-midway/core';
import { InjectEntityModel } from '@midwayjs/typeorm';
import { Repository, LessThan } from 'typeorm';
import { FlockUserEntity } from '../entity/user';

/**
 * flock模块-用户信息服务
 */
@Provide()
export class FlockUserService extends BaseService {
  @InjectEntityModel(FlockUserEntity)
  flockUserEntity: Repository<FlockUserEntity>;

  @Init()
  async init() {
    await super.init();
    this.setEntity(this.flockUserEntity);
  }

  /**
   * 获取活跃度低于指定值的用户
   * @param activityThreshold 活跃度阈值
   */
  async getUsersWithLowActivity(activityThreshold: number) {
    return this.flockUserEntity.find({
      where: {
        activity: LessThan(activityThreshold),
      },
    });
  }
}
